<?php

namespace App\Listeners;

use App\Events\RoomRegisterEvent;
use App\Http\Model\ContentCheck;
use App\Http\Model\Room;
use App\Http\Model\FinanceRoomWallet;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Log;

class RoomRegisterListener
{
    public $data;
    
    public $opType;
    
    protected $room;
    protected $roomWallet;
    protected $contentCheckModel;

    /**
     * Create the event listener.
     *
     * @return void
     */
    public function __construct(Room $room, FinanceRoomWallet $roomWallet)
    {
        //
        $this->room = $room;
        $this->roomWallet = $roomWallet;
        $this->contentCheckModel = new ContentCheck();
    }
    
    /**
     * Handle the event.
     *
     * @param $event
     * @return void
     */
    public function handle(RoomRegisterEvent $event)
    {
        //
        $data = $event->getData();
        $opType = $event->getType();
        $this->data = $data;
        $this->opType = $opType;
        switch($this->opType){
            case 1:
                $this->register();
                break;
            default:
                break;
        }
        
    }
    //房间注册
    public function register()
    {
        if (!$this->data || !$this->opType) return;
        $userId = $this->data['user_id'];
        $roomId = $this->room->create_room($this->data);
        $this->room->add_role($roomId, $userId, 2);
        $this->roomWallet->add_wallet($roomId);
        $this->room->add_collect($roomId, $userId);
    }
    
}
